package com.yuan.base.service.server.filter;

import com.yuan.base.service.infrastructure.AMIC;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lintiangang
 * @date 2021/03/26 10:18
 **/
@Slf4j
@Component
@Order(Ordered.HIGHEST_PRECEDENCE + 10)
public class BaseFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
        try {
            AMIC.init(request);
            filterChain.doFilter(request, response);
        } finally {
            AMIC.clear();
        }
    }
}
